# Makefile for building the math_lib shared library and app executable

# Compiler and flags
CXX = g++
CXXFLAGS = -Wall -fPIC

# Target names
LIB_NAME = libmath.so
APP_NAME = app

# Source files
LIB_SOURCES = math_lib.cpp
APP_SOURCES = app.cpp

# Platform-specific settings
ifeq ($(OS), Windows_NT)
    LIB_NAME = math.dll
    LDFLAGS = -shared
else
    LDFLAGS = -shared -Wl,-soname,$(LIB_NAME)
endif

# Default target
all: $(LIB_NAME) $(APP_NAME)

# Build the library (shared object)
$(LIB_NAME): $(LIB_SOURCES)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(LIB_NAME) $(LIB_SOURCES)

# Build the application and link with the library
$(APP_NAME): $(APP_SOURCES) $(LIB_NAME)
	$(CXX) $(CXXFLAGS) -o $(APP_NAME) $(APP_SOURCES) -L. -lmath -Wl,-rpath=.


# Clean the build directory
clean:
	rm -f $(LIB_NAME) $(APP_NAME)

# Phony targets
.PHONY: all clean
